package com.yunhe.springbootdemo3.controller;

import com.yunhe.springbootday1.domain.Post;
import com.yunhe.springbootday1.service.PostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
public class PostController {
    //业务层对象
    @Autowired
    private PostService postService;
    /**
     * 分页查询帖子
     * @param pageNum
     * @return
     */
    @GetMapping("/posts/{pageNum}")
    public Map<String,Object> allPosts(@PathVariable("pageNum") int pageNum){
        //调用业务方法
        Map<String,Object>  map = postService.allPosts(pageNum);
        return map;
    }
    @GetMapping("/post/{postId}")
    public Post getPostById(@PathVariable("postId") int postId){
      return postService.getPostById(postId);
    }
}
